﻿@{
    Layout = null;
}
@using AutoSchedule.Dtos.Models;
@model Organization;
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/css/layui.css" rel="stylesheet" />
</head>
<body>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>组织机构修改表单</legend>
    </fieldset>

    <form class="layui-form">
        <div class="layui-form-item" hidden="hidden">
            <label class="layui-form-label">机构编号</label>
            <div class="layui-input-block">
                <input type="text" name="CODE" lay-verify="required" autocomplete="off" placeholder="" class="layui-input" value="@Model.CODE">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">机构名称</label>
            <div class="layui-input-block">
                <input type="text" name="NAME" lay-verify="required" autocomplete="off" placeholder="" class="layui-input" value="@Model.NAME">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">数据库类型</label>
            <div class="layui-input-block">
                <select name="DBType" lay-filter="aihao" id="select">
                    <option value="0" selected="">Oracle</option>
                    <option value="1" selected="">SqlServer</option>
                    <option value="2" selected="">MySql</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">服务器名称</label>
            <div class="layui-input-block">
                <input type="text" name="ServerName" lay-verify="required" autocomplete="off" placeholder="请输入服务器名称，比如:192.168.5.7:3307" class="layui-input" value="@Model.ServerName">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">数据库名称</label>
            <div class="layui-input-block">
                <input type="text" name="DataBaseName" lay-verify="required" autocomplete="off" placeholder="请输入数据库名称" class="layui-input" value="@Model.DataBaseName">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="UserName" lay-verify="required" autocomplete="off" placeholder="" class="layui-input" value="@Model.UserName">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="Password" lay-verify="required" autocomplete="off" placeholder="" class="layui-input" value="@Model.Password">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-filter="SqlHelper" lay-submit="">测试连接</button>
                <button type="button" class="layui-btn" lay-filter="enSure" lay-submit="">确定</button>
                <button type="reset" class="layui-btn" onclick="formClose()">取消</button>
            </div>
        </div>
    </form>
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/layui.js"></script>
    <script src="~/js/bank.js"></script>

    <script type="text/javascript">
        $(function () {
            $("#select").val("@Model.DBType");
        });

        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer;

            //测试是否能够连接
            form.on('submit(SqlHelper)', function (data) {
                var dataDetail = JSON.stringify(data.field);
                console.log(dataDetail);
                $.ajax({
                    url: "/Organization/OrgSqlHelper",
                    async: true,
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;charset=UTF-8",
                    data: dataDetail,
                    success: function (dataResult) {
                            alert(dataResult.msg);
                    }
                });

            });

            form.on('submit(enSure)', function (data) {
                var dataDetail = JSON.stringify(data.field);
                console.log(dataDetail);
                $.ajax({
                    url: "/Organization/OrgEdit",
                    async: true,
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;charset=UTF-8",
                    data: dataDetail,
                    success: function (dataResult) {
                        if (dataResult.code != "0") {
                            alert(dataResult.msg);
                        }
                        var index = parent.layer.getFrameIndex(window.name);
                        setTimeout(function () { parent.layer.close(index) }, 1000);
                        setTimeout(function () { parent.location.reload() }, 100);
                    }
                });
                // window.parent.location.reload();

            });

        });
    </script>
</body>
</html>